<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="<?php echo PIUrl::createUrl('/admin');?>">Trang chủ</a>

				<span class="divider">
					<i class="icon-angle-right arrow-icon"></i>
				</span>
			</li>
			<li class="active"><?php echo translate('Theme');?></li>
		</ul>
	</div>

	<div class="page-content">
		<div class="page-header position-relative">
			<h1>
				<?php echo translate('Cập nhập theme');?>
			</h1>
		</div><!--/.page-header-->
		<div class="row-fluid">
			<div class="span12">
				<!--PAGE CONTENT BEGINS-->
				<?php $form = $this->beginWidget('CActiveForm', array(
					'id'=>'website-form',
					//'enableAjaxValidation'=>true,
					'enableClientValidation'=>true,
					'focus'=>array($model,'title'),
					'htmlOptions'=>array('class'=>'form-horizontal', 'enctype'=>'multipart/form-data'),
				)); ?>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'id_categoiresWebsite',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->dropDownList($model,'id_categoiresWebsite',$dataCategories, array('class'=>'span12')); ?>
							<?php echo $form->error($model,'id_categoiresWebsite'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($modelPrice,'id',array('class'=>'control-label checkBox')); ?>
						<div class="controls">
							<?php echo $form->checkBoxList($modelPrice, 'id', $dataPrice, array('class'=>'checkBox')); ?>
							<?php echo $form->error($modelPrice,'id'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'name',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->textField($model,'name',array('placeholder'=>'Tên webiste', 'class'=>'span12')); ?>
							<?php echo $form->error($model,'name'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'description',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->textArea($model,'description',array('placeholder'=>'Mô tả', 'class'=>'span12')); ?>
							<?php echo $form->error($model,'description'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'content',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->textArea($model,'content',array('placeholder'=>'Nội dung', 'class'=>'ckeditor')); ?>
							<?php echo $form->error($model,'content'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'price',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->textField($model,'price',array('placeholder'=>'Giá mua phần mềm', 'class'=>'span12')); ?>
							<?php echo $form->error($model,'price'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'priceFull',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->textField($model,'priceFull',array('placeholder'=>'Giá mua trộn bộ', 'class'=>'span12')); ?>
							<?php echo $form->error($model,'priceFull'); ?>
						</div>
					</div>
					
					<div class="controls">
						<img style="max-width: 500px; max-height:200px;" src="
							<?php
								echo file_exists(yii::app()->basePath."/../upload/images/".$model->image) ?
								yii::app()->baseUrl."/upload/images/".$model->image : yii::app()->baseUrl."/upload/images/noname.jpg";
							?>"/>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'image',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->fileField($model,'image',array('id'=>'id-input-file-1', 'class'=>'span12')); ?>
							<?php echo $form->error($model,'image'); ?>
						</div>
					</div>
					
					<div class="controls">
						<img style="max-width: 500px; max-height:200px;" src="
							<?php
								echo file_exists(yii::app()->basePath."/../upload/images/".$model->imageDetail) ?
								yii::app()->baseUrl."/upload/images/".$model->imageDetail : yii::app()->baseUrl."/upload/images/noname.jpg";
							?>"/>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'imageDetail',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->fileField($model,'imageDetail',array('class'=>'id-input-file-1-1 span12')); ?>
							<?php echo $form->error($model,'imageDetail'); ?>
						</div>
					</div>
					
					<div class="control-group">
						<?php echo $form->labelEx($model,'pageDemo',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php echo $form->fileField($model,'pageDemo',array('id'=>'', 'class'=>'span12 id-input-file-1-2-3')); ?>
							<?php echo $form->error($model,'pageDemo'); ?>
						</div>
					</div>
					
					<div class="widget-box  collapsed">
						<div class="widget-header">
							<h4>Thêm Hình Ảnh Demo</h4>

							<span class="widget-toolbar ">
								<button class="btn btn-primary" data-action="collapse">
								<i class="icon-chevron-up"></i>
								<?php echo translate('Thêm');?>
								</button>
								<a href="#" data-action="close">
									<i class="icon-remove"></i>
								</a>
							</span>
						</div>

						<div class="widget-body">
							<div class="widget-main">
								<input type="file" name="images[]" id="id-input-file-3" multiple='true' />
								<label>
									<input checked="true" type="checkbox" name="file-format" id="id-file-format" />
									<span class="lbl"> Chỉ cho phép hình ảnh</span>
								</label>
							</div>
						</div>
					</div>
					
					<ul class="ace-thumbnails">
					<?php if(!empty($arrImageTheme)){ foreach($arrImageTheme as $image):?>
						<li>
							<a href="javascript:void(0)">
								<img width="150px" height="150px"  src="<?php echo getImage($image->image,150,150,1);?>" />
							</a>

							<div class="tools tools-bottom">
								<a href="<?php echo $image->id; ?>" class="delete">
									<i class="icon-remove red"></i>
								</a>
							</div>

						</li>
						<?php endforeach; }else{?>
						<span>Không có hình ảnh</span>
						<?php }?>				
					</ul>
					
					<div class="form-actions" style="clear:both">
						<button id="submitForm" class="btn btn-primary" type="submit">
							<i class="icon-ok bigger-110"></i>
							<?php echo translate('Cập nhập');?>
						</button>

						&nbsp; &nbsp; &nbsp;
						<button type="button" onclick="location.href='<?php echo PIUrl::createUrl('/admin');?>'" class="btn" >
							<i class="icon-undo bigger-110"></i>
							<?php echo translate('hủy');?>
						</button>
					</div>
				<?php $this->endWidget(); ?>
			</div><!--/.span-->
		</div><!--/.row-fluid-->
	</div><!--/.page-content-->
	</div><!--/.main-content-->
<script>
	$("#website-form").submit(function(){
		error = true;
		$("input.checkBox").each(function(){
			if($(this).attr("checked") == "checked") error = false;
		});
		if(error == true){	
			alert("Vui lòng điền chọn gói theme!");
			return false;
		}else{
			$("#submitForm").attr("disabled", true);
		}
	});
	
	$(document).ready(function(){
		$(".delete").click(function(){
			$(this).parent().parent().attr("class", "clicked");
			data = $(this).attr("href");
			$.ajax({
				url:"<?php echo PIUrl::createUrl('/admin/websites/deleteImage/'); ?>"+"?id="+data,
				success:function(result){
					if(result == true){
						$(".clicked").remove();
					}else{
						alert("Xóa hình ảnh không thành công!");
					}
				}
			});			
			return false;
		});
		
		$('.id-input-file-1-2-3').ace_file_input({
			no_file:'No File ...',
			btn_choose:'Chọn file',
			btn_change:'Thay đổi',
			droppable:false,
			onchange:null,
			before_change:before_change,
			thumbnail:false, //| true | large
			//whitelist:'gif|png|jpg|jpeg'
			blacklist:'exe|php'
			//onchange:''
		});
		
		$('#id-input-file-1 , .id-input-file-1-1').ace_file_input({
			no_file:'No File ...',
			btn_choose:'Chọn file',
			btn_change:'Thay đổi',
			droppable:false,
			onchange:null,
			before_change:before_change_image,
			thumbnail:false, //| true | large
			//whitelist:'gif|png|jpg|jpeg'
			blacklist:'exe|php'
			//onchange:''
		});
	})
	
	
	// validate khi upload file .zip
	before_change = function(files, dropped) {
		var allowed_files = [];
		for(var i = 0 ; i < files.length; i++) {
			var file = files[i];
			if(typeof file === "string") {
				//IE8 and browsers that don't support File Object
				if(! (/\.(zip)$/i).test(file) ) return false;
			}
			else {
			
				var type =   file.name.split('.').pop().toLowerCase();

				if( ( type.length > 0 && (/\.zip$/).test(file.name))
						//for android's default browser which gives an empty string for file.type
					)	allowed_files.push(file);
				else	continue;//not an image so don't keep this file
			}
		}
		if(allowed_files.length == 0) {message('Chỉ cho phép tải file .zip .','error'); return false};
		return allowed_files;
	}
	
	// validate khi upload file hinh anh
	before_change_image = function(files, dropped) {
		var allowed_files = [];
		for(var i = 0 ; i < files.length; i++) {
			var file = files[i];
			if(typeof file === "string") {
				//IE8 and browsers that don't support File Object
				if(! (/\.(jpe?g|png|gif|bmp)$/i).test(file) ) return false;
			}
			else {
				var type = $.trim(file.type);
				if( ( type.length > 0 && ! (/^image\/(jpe?g|png|gif|bmp)$/i).test(type) )
						|| ( type.length == 0 && ! (/\.(jpe?g|png|gif|bmp)$/i).test(file.name) )//for android's default browser which gives an empty string for file.type
					) continue;//not an image so don't keep this file
			}
			
			allowed_files.push(file);
		}
		if(allowed_files.length == 0) {message('Chỉ cho phép tải lên hình ảnh.','error'); return false};
		if(allowed_files[0].size > 2048000) {message('Kích thước ảnh quá lớn(phải nhỏ hơn 2048KB).','error'); return false};
		return allowed_files;
	}
</script>
<style>
.checkBox{
	display:inline !important;
	opacity:1 !important;
	position:relative !important;
}
#Prices_id label{display:inline !important;}
</style>